<?php

namespace App\Models;


class AuthGroup extends BaseModel
{
    protected $table = "auth_group";

    public $timestamps = false;

    public function __construct()
    {
        parent::__construct();
    }

    public function addOrUpdate()
    {
        if (request()->has('id')) {
            $data['id'] = request('id');
        }
        $data['title'] = request('title');
        if (!$data['title']) {
            $this->error = '必须设置用户组标题';
            return false;
        }
        if (request()->has('rules')) {
            $rules = request('rules');
            sort($rules);
            $data['rules'] = implode(',', array_unique($rules));
        }
        if (request()->has('description')) {
            $data['description'] = request('description');
            if ($data['description'] && strlen($data['description']) > 80) {
                $this->error = '描述最多80字符';
                return false;
            }
        }
        $res = $this->_save($data);
        if (!$res) {
            $this->error = '操作失败';
            return false;
        }
        return '操作成功!';
    }


    
}